import 'package:flutter/material.dart';

import 'package:yp/config/style.dart';
import 'package:yp/utils/util.dart';
import 'package:yp/Xwidgets/button_widget.dart';
import 'package:yp/Xwidgets/index.dart';

import '../helper.dart';
//import 'package:flutter_screenutil/flutter_screenutil.dart';

typedef ClickCallback = void Function(int selectIndex, String selectString,
    {Map<String, dynamic> info});


class YpBottomSheet {

  /// 弹出底部文字
  static void showText(BuildContext context, List<String> titleList,
      {String title, bool showRedText = false, ClickCallback clickCallback}) {
    int maxIndex = titleList.length ?? 0;
    maxIndex = maxIndex > 8 ? 8 : maxIndex;

    showModalBottomSheet(
        context: context,
        isScrollControlled: true,
        builder: (BuildContext context) {
          return AnimatedPadding(
              padding: MediaQuery.of(context).viewInsets,
              duration: const Duration(milliseconds: 100),
              child: Container(
                color: EsColors.White,
                constraints: BoxConstraints(
                    minHeight: 120, maxHeight: maxIndex * 40 + 50.0),
                child: Column(
                  children: <Widget>[
                    Visibility(
                      visible: title?.isNotEmpty ?? false,
                      child: Padding(
                        padding: EdgeInsets.only(top: 20),
                        child: Text(title ?? "",
                            style: TextStyle(
                                fontSize: EsSizes.SM,
                                color: EsColors.Content,
                                fontWeight: EsFontWeights.Normal),
                            textAlign: TextAlign.center),
                      ),
                    ),
                    Container(
                      constraints: BoxConstraints(
                        minHeight: 50,
                        maxHeight: maxIndex * 40.0,
                      ),
                      child: ListView.separated(
                        itemCount: titleList?.length ?? 0,
                        shrinkWrap: true,
                        padding: EdgeInsets.zero,
                        itemBuilder: (BuildContext context, int index) {
                          return GestureDetector(
                            child: Container(
                              alignment: Alignment.center,
                              height: 40,
                              color: Colors.white,
                              child: Text(titleList[index] ?? '',
                                  style: TextStyle(
                                      fontSize: EsSizes.SM,
                                      color: EsColors.Content,
                                      fontWeight: EsFontWeights.Normal)),
                            ),
                            onTap: () {
                              clickCallback(index, titleList[index]);
                              Navigator.of(context).pop(index);
                            },
                          );
                        },
                        separatorBuilder: (context, index) => Container(
                            color: EsColors.BackGroundSecondary, height: 1),
                      ),
                    ),
                    Container(color: EsColors.BackGroundSecondary, height: 1),
                    GestureDetector(
                      onTap: () {
                        Navigator.of(context).pop();
                      },
                      child: Container(
                          height: 40,
                          alignment: Alignment.center,
                          color: EsColors.White,
                          child: Text('取消',
                              style: TextStyle(
                                  fontSize: EsSizes.SM,
                                  fontWeight: EsFontWeights.Normal,
                                  color: showRedText
                                      ? EsColors.Primary
                                      : EsColors.Content))),
                    )
                  ],
                ),
              ));
        });
  }

  ///  弹出带X 带选择框 按钮的地库弹出框
  static void showSelect(BuildContext context, List<String> titleList,
      {String title, int selectIndex, ClickCallback clickCallback}) {
    List<Map<String, dynamic>> selectMapList = [];
    int maxIndex = titleList.length ?? 0;
    maxIndex = maxIndex > 6 ? 6 : maxIndex;
    for (var i = 0; i < titleList.length; i++) {
      selectMapList.add({'select': (i == selectIndex)});
    }

    showModalBottomSheet(
        context: context,
        isScrollControlled: true,
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(15), topRight: Radius.circular(15))),
        builder: (BuildContext context) {
          return StatefulBuilder(builder: (context1, state1) {
            return AnimatedPadding(
                padding: MediaQuery.of(context).viewInsets,
                duration: const Duration(milliseconds: 100),
                child: Stack(
                  children: [
                    Container(
                      padding: EdgeInsets.only(top: 20),
                      decoration: BoxDecoration(
                        color: EsColors.White,
                        borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(15),
                            topRight: Radius.circular(15)),
                      ),
                      constraints: BoxConstraints(
                        minHeight: 90,
                        maxHeight: maxIndex * 50 +
                            60.0 +
                            MediaQuery.of(context).padding.bottom,
                      ),
                      child: Column(
                        children: <Widget>[
                          Row(
                            children: [
                              SizedBox(width: 36),
                              Expanded(
                                child: Text(title ?? "",
                                    style: TextStyle(
                                        fontSize: EsSizes.SM,
                                        color: EsColors.Content,
                                        fontWeight: EsFontWeights.Normal),
                                    textAlign: TextAlign.center),
                              ),
                              EsIconButton(
                                Icon(
                                  Icons.close,
                                  size: 24,
                                  color: EsColors.Fill,
                                ),
                                padding: EdgeInsets.only(right: 12),
                                onTap: () {
                                  Navigator.of(context).pop();
                                },
                              )
                            ],
                          ),
                          Container(
                            constraints: BoxConstraints(
                              minHeight: 50,
                              maxHeight: maxIndex * 50.0,
                            ),
                            child: ListView.separated(
                              itemCount: titleList?.length ?? 0,
                              shrinkWrap: true,
                              padding: EdgeInsets.only(
                                  left: 12,
                                  bottom:
                                      MediaQuery.of(context).padding.bottom +
                                          60),
                              itemBuilder: (BuildContext context, int index) {
                                return GestureDetector(
                                  child: Container(
                                      height: 50,
                                      color: Colors.white,
                                      child: Row(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        mainAxisAlignment:
                                            MainAxisAlignment.start,
                                        children: [
                                          Expanded(
                                            child: Text(titleList[index] ?? '',
                                                style: TextStyle(
                                                    fontSize: EsSizes.SM,
                                                    color:
                                                        EsColors.TitleSecondary,
                                                    fontWeight:
                                                        EsFontWeights.Normal)),
                                          ),
                                          Icon(
                                              selectMapList[index]['select']
                                                  ? Icons.radio_button_checked
                                                  : Icons
                                                      .radio_button_unchecked,
                                              size: 16,
                                              color: selectMapList[index]
                                                      ['select']
                                                  ? EsColors.Primary
                                                  : EsColors.Fill),
                                          SizedBox(width: 12)
                                        ],
                                      )),
                                  onTap: () {
                                    state1(() {
                                      selectIndex = index;
                                      for (var i = 0;
                                          i < selectMapList.length;
                                          i++) {
                                        selectMapList[i]['select'] =
                                            i == selectIndex;
                                      }
                                    });
                                  },
                                );
                              },
                              separatorBuilder: (context, index) => SizedBox(),
                            ),
                          ),
                          SizedBox(height: 10),
                        ],
                      ),
                    ),
                    Positioned(
                        left: 0,
                        right: 0,
                        bottom: 0,
                        child: Container(
                          height: 60,
                          color: EsColors.White,
                          child: EsBottomWidget(
                              decoration: null,
                              fontSize: EsSizes.SM,
                              leftTitle: null,
                              rightTitle: '提交',
                              rightlick: () {
                                if (selectIndex != null) {
                                  Navigator.of(context).pop(selectIndex);
                                  clickCallback(
                                      selectIndex, titleList[selectIndex]);
                                } else {}
                              }),
                        ))
                  ],
                ));
          });
        });
  }

  /// 支付方式
  static void showPayWay(BuildContext context, ClickCallback clickCallback) {
    int index = 0;
    showModalBottomSheet(
        context: context,
        // isDismissible: true,
        isScrollControlled: true,
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(15), topRight: Radius.circular(15))),
        builder: (BuildContext context) {
          return StatefulBuilder(builder: (context1, state1) {
            return AnimatedPadding(
                //showModalBottomSheet 键盘弹出时自适应
                padding: MediaQuery.of(context).viewInsets,
                duration: const Duration(milliseconds: 100),
                child: Container(
                    constraints: BoxConstraints(
                      minHeight: 90,
                      maxHeight: MediaQuery.of(context).size.height / 1.2,
                    ),
                    child: ListView(shrinkWrap: true, children: [
                      Container(
                          alignment: Alignment.bottomCenter,
                          padding: EdgeInsets.only(top: 12),
                          child: Row(
                            children: [
                              SizedBox(width: 36),
                              Expanded(
                                child: Text('选择支付方式',
                                    style: TextStyle(
                                        fontSize: EsSizes.MD,
                                        color: EsColors.Content,
                                        fontWeight: EsFontWeights.Normal),
                                    textAlign: TextAlign.center),
                              ),
                              EsIconButton(
                                Icon(
                                  Icons.close,
                                  size: 24,
                                  color: EsColors.Fill,
                                ),
                                padding: EdgeInsets.only(right: 12),
                                onTap: () {
                                  Navigator.of(context).pop();
                                },
                              )
                            ],
                          )),
                      Padding(
                        padding: const EdgeInsets.symmetric(
                            horizontal: 12, vertical: 20),
                        child: Row(
                          children: [
                            Image.asset('assets/images/selectIcon1.png',
                                width: 16, height: 16),
                            SizedBox(
                              width: 8,
                            ),
                            Text(
                              '福利卡（已选2张，共5张）',
                              style: TextStyle(
                                  color: EsColors.TitleSecondary,
                                  fontSize: EsSizes.MD,
                                  fontWeight: EsFontWeights.Normal),
                            ),
                            Expanded(
                                child: Text(
                              '￥100.00',
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              textAlign: TextAlign.end,
                              style: TextStyle(
                                  color: EsColors.TitleSecondary,
                                  fontSize: EsSizes.MD,
                                  fontWeight: EsFontWeights.Medium),
                            ))
                          ],
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(left: 36, bottom: 18),
                        height: 155,
                        child: ListView.builder(
                            itemCount: 5,
                            scrollDirection: Axis.horizontal,
                            shrinkWrap: true,
                            itemBuilder: (context, index) {
                              return GestureDetector(
                                onTap: () {
                                  print('选择礼品卡');
                                },
                                child: Stack(children: [
                                  Container(
                                    width: 190,
                                    padding: EdgeInsets.all(6),
                                    margin: EdgeInsets.only(right: 10),
                                    child: Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      mainAxisAlignment:
                                          MainAxisAlignment.start,
                                      children: [
                                        CachedImage(
                                            width: 176,
                                            height: 100,
                                            padding: EdgeInsets.zero,
                                            scale: BoxFit.fitWidth,
                                            path:
                                                'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01475456c17a516ac7256cb073bfa3.png%401280w_1l_2o_100sh.png&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633444036&t=ca44f607bd0eae33f65c55c182a49e6e'),
                                        Expanded(child: SizedBox(height: 2)),
                                        Text(
                                          '中秋节福利卡',
                                          style: TextStyle(
                                              color: EsColors.TitleSecondary,
                                              fontSize: EsSizes.XS,
                                              fontWeight: EsFontWeights.Normal),
                                        ),
                                        Row(
                                          children: [
                                            Expanded(
                                              child: Text(
                                                '￥500.00',
                                                maxLines: 1,
                                                overflow: TextOverflow.ellipsis,
                                                style: TextStyle(
                                                    color:
                                                        EsColors.TitleSecondary,
                                                    fontSize: EsSizes.XS,
                                                    fontWeight:
                                                        EsFontWeights.Medium),
                                              ),
                                            ),
                                            Text(
                                              '有效期至:2019-09-21',
                                              style: TextStyle(
                                                  color: EsColors.Fill,
                                                  fontSize: EsSizes.XXS,
                                                  fontWeight:
                                                      EsFontWeights.Normal),
                                            )
                                          ],
                                        )
                                      ],
                                    ),
                                    decoration: BoxDecoration(
                                        color: EsColors.White,
                                        border: Border.all(
                                          color: EsColors.Primary,
                                          width: 1,
                                        ),
                                        borderRadius: BorderRadius.circular(3)),
                                  ),
                                  Positioned(
                                      left: 0,
                                      top: 0,
                                      child: Image.asset(
                                          'assets/images/selected_left.png',
                                          width: 47,
                                          height: 47))
                                ]),
                              );
                            }),
                      ),
                      YpLine(),
                      GestureDetector(
                        behavior: HitTestBehavior.opaque,
                        onTap: () {
                          state1(() {
                            index = 0;
                            print('切换支付方式微信');
                          });
                        },
                        child: Padding(
                          padding: const EdgeInsets.symmetric(
                              horizontal: 12, vertical: 20),
                          child: Row(
                            children: [
                              Image.asset(
                                  index == 0
                                      ? 'assets/images/selectIcon1.png'
                                      : 'assets/images/select1.png',
                                  width: 16,
                                  height: 16),
                              SizedBox(
                                width: 8,
                              ),
                              Text(
                                '微信支付',
                                style: TextStyle(
                                    color: EsColors.TitleSecondary,
                                    fontSize: EsSizes.MD,
                                    fontWeight: EsFontWeights.Normal),
                              ),
                              Expanded(
                                  child: Text(
                                '￥100.00',
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                textAlign: TextAlign.end,
                                style: TextStyle(
                                    color: EsColors.TitleSecondary,
                                    fontSize: EsSizes.MD,
                                    fontWeight: EsFontWeights.Medium),
                              ))
                            ],
                          ),
                        ),
                      ),
                      YpLine(),
                      GestureDetector(
                        behavior: HitTestBehavior.opaque,
                        onTap: () {
                          state1(() {
                            index = 1;
                            print('切换支付方式支付宝');
                          });
                        },
                        child: Padding(
                          padding: const EdgeInsets.symmetric(
                              horizontal: 12, vertical: 20),
                          child: Row(
                            children: [
                              Image.asset(
                                  index == 1
                                      ? 'assets/images/selectIcon1.png'
                                      : 'assets/images/select1.png',
                                  width: 16,
                                  height: 16),
                              SizedBox(
                                width: 8,
                              ),
                              Text(
                                '支付宝支付',
                                style: TextStyle(
                                    color: EsColors.TitleSecondary,
                                    fontSize: EsSizes.MD,
                                    fontWeight: EsFontWeights.Normal),
                              ),
                              Expanded(
                                  child: Text(
                                '￥100.00',
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                textAlign: TextAlign.end,
                                style: TextStyle(
                                    color: EsColors.TitleSecondary,
                                    fontSize: EsSizes.MD,
                                    fontWeight: EsFontWeights.Medium),
                              ))
                            ],
                          ),
                        ),
                      ),
                      YpLine(),
                      SizedBox(height: 27),
                      Center(
                        child: RichText(
                          text: TextSpan(
                            children: [
                              TextSpan(
                                text: '应付：',
                                style: TextStyle(
                                    color: EsColors.Primary,
                                    fontSize: EsSizes.XS,
                                    fontWeight: EsFontWeights.Normal),
                              ),
                              TextSpan(
                                text: '￥422.08',
                                style: TextStyle(
                                    color: EsColors.Primary,
                                    fontSize: EsSizes.LG,
                                    fontWeight: EsFontWeights.Medium),
                              )
                            ],
                          ),
                        ),
                      ),
                      SizedBox(height: 16),
                      EsBottomWidget(
                          leftTitle: null,
                          rightTitle: '确认付款',
                          rightlick: () {
                            print('确认付款');
                            Navigator.of(context).pop();
                            clickCallback(index, index == 0 ? '微信' : '支付宝',
                                info: {'gift': ''});
                          },
                          decoration: null)
                    ])));
          });
        });
  }

  /// 分享有礼
  static void showShareGift(BuildContext context, ClickCallback clickCallback,{title}) {
    var tit ='分享有礼';
    if(title!=null){
      tit = title;
    }
    List channellist = [
      {'name': '分享到微信', 'image': 'assets/images/share1.png'},
       {'name': '分享到朋友圈', 'image': 'assets/images/pyq.png'},
      // {'name': '分享到微信', 'image': 'assets/images/share1.png'},
      // {'name': '图文卡片', 'image': 'assets/images/share2.png'}
    ];
    showModalBottomSheet(
        context: context,
        // isDismissible: true,
        isScrollControlled: true,
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(15), topRight: Radius.circular(15))),
        builder: (BuildContext context) {
          return StatefulBuilder(builder: (context1, state1) {
            return AnimatedPadding(
                //showModalBottomSheet 键盘弹出时自适应
                padding: MediaQuery.of(context).viewInsets,
                duration: const Duration(milliseconds: 100),
                child: Container(
                    // height: 200 + MediaQuery.of(context).padding.bottom,
                    constraints: BoxConstraints(
                      minHeight: 200,
                      maxHeight: 220 + MediaQuery.of(context).padding.bottom,
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        SizedBox(height: 20),
                        Text(tit,
                            style: TextStyle(
                                fontSize: EsSizes.MD,
                                color: EsColors.TitleSecondary,
                                fontWeight: EsFontWeights.Normal),
                            textAlign: TextAlign.center),
                        SizedBox(height: 16),
                        Text('',
                            style: TextStyle(
                                fontSize: EsSizes.SM,
                                color: EsColors.ContentSecondary,
                                fontWeight: EsFontWeights.Normal),
                            textAlign: TextAlign.center),
                        SizedBox(height: 22),
                        SizedBox(
                          height: 80,
                          child: ListView.builder(
                              shrinkWrap: true,
                              // padding:  EdgeInsets.only(left: 30),
                              scrollDirection: Axis.horizontal,
                              itemCount: channellist.length,
                              itemBuilder: (context, index) {
                                return SizedBox(
                                    width: MediaQuery.of(context).size.width /
                                        (channellist.length > 3
                                            ? 3
                                            : channellist.length),
                                    child: GestureDetector(
                                      onTap: () {
                                        Navigator.of(context).pop();
                                        clickCallback(
                                            index, channellist[index]['name']);
                                      },
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        children: [
                                          Image.asset(
                                              channellist[index]['image'],
                                              width: 48,
                                              height: 48),
                                          SizedBox(height: 12),
                                          Text(channellist[index]['name'],
                                              style: TextStyle(
                                                  fontSize: EsSizes.XS,
                                                  color: EsColors.Title,
                                                  fontWeight:
                                                      EsFontWeights.Normal))
                                        ],
                                      ),
                                    ));
                              }),
                        ),
                        SizedBox(height: 20)
                      ],
                    )));
          });
        });
  }

  /// 优惠券
  static void showCoupon(BuildContext context,
      List<Map<String, dynamic>> couponList, ClickCallback clickCallback) {
    int maxIndex = couponList.length ?? 0;
    int selectIndex;
    maxIndex = maxIndex > 3 ? 3 : maxIndex;
    for (var i = 0; i < couponList.length; i++) {
      if (couponList[i]['isSelected']) {
        selectIndex = i;
      }
    }

    showModalBottomSheet(
        context: context,
        // isDismissible: true,
        isScrollControlled: true,
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(15), topRight: Radius.circular(15))),
        builder: (BuildContext context) {
          return StatefulBuilder(builder: (context1, state1) {
            return AnimatedPadding(
                //showModalBottomSheet 键盘弹出时自适应
                padding: MediaQuery.of(context).viewInsets,
                duration: const Duration(milliseconds: 100),
                child: Container(
                    constraints: BoxConstraints(
                      minHeight: 90,
                      maxHeight: maxIndex * 110.0 +
                          120 +
                          MediaQuery.of(context).padding.bottom,
                    ),
                    child: Stack(
                      children: [
                        Container(
                          padding: EdgeInsets.only(
                              bottom:
                                  MediaQuery.of(context).padding.bottom + 60,
                              top: 16),
                          child: Column(
                            children: [
                              Text('可用优惠券',
                                  style: TextStyle(
                                      fontSize: EsSizes.SM,
                                      color: EsColors.Content,
                                      fontWeight: EsFontWeights.Normal)),
                              SizedBox(height: 12),
                              Container(
                                constraints: BoxConstraints(
                                  minHeight: 50,
                                  maxHeight: maxIndex * 110.0,
                                ),
                                child: ListView.builder(
                                    shrinkWrap: true,
                                    padding: EdgeInsets.fromLTRB(8, 4, 8, 4),
                                    // physics: NeverScrollableScrollPhysics(),
                                    itemCount: couponList.length,
                                    itemBuilder: (context, index) {
                                      return GestureDetector(
                                        onTap: () {
                                          print('选中');
                                          state1(() {
                                            for (var i = 0;
                                                i < couponList.length;
                                                i++) {
                                              if (i == index) {
                                                couponList[i]['isSelected'] =
                                                    !couponList[i]
                                                        ['isSelected'];
                                              } else {
                                                couponList[i]['isSelected'] =
                                                    false;
                                              }
                                              selectIndex = couponList[index]
                                                      ['isSelected']
                                                  ? index
                                                  : null;
                                            }
                                          });
                                        },
                                        behavior: HitTestBehavior.opaque,
                                        child: Container(
                                          // width: double.infinity,
                                          height: 110,
                                          padding: EdgeInsets.symmetric(
                                              horizontal: 12),
                                          child: Row(
                                            children: [
                                              Container(
                                                // color: EsColors.Pink,
                                                width: MediaQuery.of(context)
                                                        .size
                                                        .width /
                                                    4,
                                                child: Column(
                                                  mainAxisAlignment:
                                                      MainAxisAlignment.center,
                                                  children: [
                                                    RichText(
                                                      maxLines: 1,
                                                      overflow:
                                                          TextOverflow.ellipsis,
                                                      text: TextSpan(
                                                          text: '￥',
                                                          style: TextStyle(
                                                              fontSize:
                                                                  EsSizes.MD,
                                                              color: EsColors
                                                                  .Money,
                                                              fontWeight:
                                                                  EsFontWeights
                                                                      .Medium),
                                                          children: <TextSpan>[
                                                            TextSpan(
                                                                text: couponList[
                                                                            index]
                                                                        [
                                                                        'amount']
                                                                    .toString(),
                                                                style: TextStyle(
                                                                    fontSize:
                                                                        40,
                                                                    color: EsColors
                                                                        .Money,
                                                                    fontWeight:
                                                                        EsFontWeights
                                                                            .Bold)),
                                                          ]),
                                                    ),
                                                    Text(
                                                      '满59元可用',
                                                      maxLines: 1,
                                                      overflow:
                                                          TextOverflow.ellipsis,
                                                      style: TextStyle(
                                                          fontSize: EsSizes.XXS,
                                                          color: EsColors.Money,
                                                          fontWeight:
                                                              EsFontWeights
                                                                  .Medium),
                                                    )
                                                  ],
                                                ),
                                              ),
                                              Expanded(
                                                child: Padding(
                                                  padding:
                                                      const EdgeInsets.fromLTRB(
                                                          30, 25, 8, 25),
                                                  child: Column(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .spaceEvenly,
                                                    crossAxisAlignment:
                                                        CrossAxisAlignment
                                                            .start,
                                                    children: [
                                                      Expanded(
                                                        child: Text(
                                                          '嘉定万达开业活动送券店铺',
                                                          maxLines: 2,
                                                          overflow: TextOverflow
                                                              .ellipsis,
                                                          style: TextStyle(
                                                              fontSize:
                                                                  EsSizes.SM,
                                                              color: EsColors
                                                                  .Title,
                                                              fontWeight:
                                                                  EsFontWeights
                                                                      .Medium),
                                                        ),
                                                      ),
                                                      Text(
                                                        '2019.09.10-2019.12.12',
                                                        maxLines: 1,
                                                        overflow: TextOverflow
                                                            .ellipsis,
                                                        style: TextStyle(
                                                            fontSize:
                                                                EsSizes.XS,
                                                            color:
                                                                EsColors.Money,
                                                            fontWeight:
                                                                EsFontWeights
                                                                    .Light),
                                                      )
                                                    ],
                                                  ),
                                                ),
                                              ),
                                              SizedBox(width: 8),
                                              Image.asset(
                                                  couponList[index]
                                                          ['isSelected']
                                                      ? 'assets/images/selectIcon1.png'
                                                      : 'assets/images/select1.png',
                                                  width: 16,
                                                  height: 16),
                                            ],
                                          ),
                                          decoration: BoxDecoration(
                                            image: DecorationImage(
                                                fit: BoxFit.fitWidth,
                                                image: AssetImage(
                                                    'assets/images/coupon.png')),
                                          ),
                                        ),
                                      );
                                    }),
                              ),
                            ],
                          ),
                        ),
                        Positioned(
                            left: 0,
                            right: 0,
                            bottom: MediaQuery.of(context).padding.bottom + 0,
                            child: Container(
                              height: 60,
                              color: EsColors.White,
                              child: EsBottomWidget(
                                  decoration: null,
                                  fontSize: EsSizes.SM,
                                  leftTitle: null,
                                  rightTitle: '确定',
                                  rightlick: () {
                                    if (selectIndex != null) {
                                      Navigator.of(context).pop(selectIndex);
                                      clickCallback(selectIndex, '',
                                          info: couponList[selectIndex]);
                                    } else {
                                      toast('请选择优惠券');
                                    }
                                  }),
                            ))
                      ],
                    )));
          });
        });
  }

  /// 商品规格
  static void showSpecification(BuildContext context,
      List<Map<String, dynamic>> specList, ClickCallback clickCallback) {
    showModalBottomSheet(
        context: context,
        // isDismissible: true,
        isScrollControlled: true,
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(15), topRight: Radius.circular(15))),
        builder: (BuildContext context) {
          return StatefulBuilder(builder: (context1, state1) {
            return Container(
                constraints: BoxConstraints(
                  minHeight: 300,
                  maxHeight: MediaQuery.of(context).size.height / 1.5,
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Padding(
                      padding: EdgeInsets.fromLTRB(12, 18, 12, 20),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          CachedImage(
                              width: 90,
                              height: 90,
                              padding: EdgeInsets.zero,
                              scale: BoxFit.cover,
                              path:
                                  'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnimg.ws.126.net%2F%3Furl%3Dhttp%253A%252F%252Fdingyue.ws.126.net%252F2021%252F0908%252F8da083a9j00qz41qp007ec000md00f6m.jpg%26thumbnail%3D650x2147483647%26quality%3D80%26type%3Djpg&refer=http%3A%2F%2Fnimg.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633703439&t=591a982e2fef8ab5a74d155aa42a153e'),
                          SizedBox(width: 10),
                          SizedBox(
                            height: 90,
                            child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  Text('￥189.00',
                                      style: TextStyle(
                                          color: EsColors.Primary,
                                          fontSize: EsSizes.XL,
                                          fontWeight: EsFontWeights.Medium)),
                                  SizedBox(height: 6),
                                  Text('库存：344',
                                      style: TextStyle(
                                          color: EsColors.ContentSecondary,
                                          fontSize: EsSizes.XS,
                                          fontWeight: EsFontWeights.Normal)),
                                  SizedBox(height: 6),
                                  Text('已选：优惠127个装；5.5、38',
                                      style: TextStyle(
                                          color: EsColors.ContentSecondary,
                                          fontSize: EsSizes.XS,
                                          fontWeight: EsFontWeights.Normal))
                                ]),
                          ),
                          Expanded(child: SizedBox()),
                          EsIconButton(
                            Icon(Icons.close, size: 24, color: EsColors.Fill),
                            onTap: () {
                              Navigator.of(context).pop();
                            },
                          )
                        ],
                      ),
                    ),
                    Container(
                        color: EsColors.Line,
                        height: 1,
                        width: double.infinity),
                    Expanded(
                      child: ListView.builder(
                          // physics: NeverScrollableScrollPhysics(),
                          padding: EdgeInsets.fromLTRB(12, 22, 12, 22),
                          shrinkWrap: true,
                          itemCount: specList.length,
                          itemBuilder: (context, index) {
                            return Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  specList[index]['name'],
                                  style: TextStyle(
                                      color: EsColors.TitleSecondary,
                                      fontSize: EsSizes.SM,
                                      fontWeight: EsFontWeights.Normal),
                                ),
                                SizedBox(height: 8),
                                Wrap(
                                  spacing: 10,
                                  runSpacing: 10,
                                  children: List.generate(
                                      specList[index]['list'].length,
                                      (item) => EsOutLineButton(
                                            specList[index]['list'][item]
                                                ['name'],
                                            textColor: specList[index]['list']
                                                    [item]['isSelect']
                                                ? EsColors.White
                                                : EsColors.TitleSecondary,
                                            fontSize: EsSizes.XS,
                                            fontWeight: EsFontWeights.Normal,
                                            bgColor: specList[index]['list']
                                                    [item]['isSelect']
                                                ? EsColors.Primary
                                                : EsColors.White,
                                            padding: EdgeInsets.symmetric(
                                                vertical: 4, horizontal: 12),
                                            normal: !specList[index]['list']
                                                [item]['isSelect'],
                                            onTap: () {
                                              print(specList[index]['list']
                                                  [item]['name']);
                                              state1(() {
                                                specList[index]['list'][item]
                                                        ['isSelect'] =
                                                    !specList[index]['list']
                                                        [item]['isSelect'];
                                              });
                                            },
                                          )),
                                ),
                                SizedBox(height: 20),
                              ],
                            );
                          }),
                    ),
                    Container(
                        color: EsColors.Line,
                        height: 1,
                        width: double.infinity),
                    Padding(
                      padding: const EdgeInsets.symmetric(horizontal: 12),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text('数量',
                              style: TextStyle(
                                  color: EsColors.TitleSecondary,
                                  fontSize: EsSizes.SM,
                                  fontWeight: EsFontWeights.Normal)),
                          Row(
                            children: [
                              IconButton(
                                  onPressed: () {
                                    print('sub');
                                  },
                                  icon: Image(
                                    image:
                                        AssetImage("assets/images/reduce.png"),
                                    width: 22,
                                  )),
                              Text('1',
                                  style: TextStyle(
                                      fontSize: EsSizes.LG,
                                      color: EsColors.TitleSecondary,
                                      fontWeight: EsFontWeights.Normal)),
                              IconButton(
                                  onPressed: () {
                                    print('add');
                                  },
                                  icon: Image(
                                    image: AssetImage("assets/images/plus.png"),
                                    width: 22,
                                  )),
                            ],
                          )
                        ],
                      ),
                    ),
                    Container(
                      padding: EdgeInsets.fromLTRB(12, 10, 12,
                          MediaQuery.of(context).padding.bottom / 2 + 10),
                      alignment: Alignment.center,
                      child: EsOutLineButton(
                        '确定',
                        fontSize: EsSizes.MD,
                        bgColor: EsColors.Primary,
                        textColor: EsColors.White,
                        borderRadius: 30,
                        padding: EdgeInsets.symmetric(
                            horizontal:
                                MediaQuery.of(context).size.width / 2 - 36,
                            vertical: 12),
                        onTap: () {
                          clickCallback(null, null, info: {'list': specList});
                          Navigator.of(context).pop();
                        },
                      ),
                    )
                  ],
                ));
          });
        });
  }
}

///选择 快递公司
Future<Map<String, dynamic>> selectDelivery(BuildContext context) async {
  Map<String, dynamic> result = await showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            ListTile(
              title: const Center(child: Text('中通')),
              onTap: () async {
                Navigator.pop(context, {'id': '1', 'name': '中通'});
              },
            ),
            ListTile(
              title: const Center(child: Text('圆通')),
              onTap: () async {
                Navigator.pop(context, {'id': '2', 'name': '圆通'});
              },
            ),
            ListTile(
              title: const Center(child: Text('申通')),
              onTap: () async {
                Navigator.pop(context, {'id': '2', 'name': '申通'});
              },
            ),
            ListTile(
              title: const Center(child: Text('韵达')),
              onTap: () async {
                Navigator.pop(context, {'id': '2', 'name': '韵达'});
              },
            ),
            SizedBox(
              height: MediaQuery.of(context).padding.bottom + 10,
            )
          ],
        );
      });
  return result ?? {};
}
